package org.openstreetmap.gui.jmapviewer;

//License: GPL. Copyright 2008 by Jan Peter Stotz

import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;

/**
 * A simple implementation of the {@link MapMarker} interface. Each map marker
 * is painted as a circle with a black border line and filled with a specified
 * markerBackground.
 *
 * @author Jan Peter Stotz
 *
 */
public class MapMarkerDot implements MapMarker {

	private Color colorBackground;
	private Color colorBorder;

	private double lat;
	private double lon;
	private double altitude;

    private Color color;
	private long timestamp;
	private double distanceToPreviousMarker;

	private boolean isInLocation = false;
	private int mapLocationID;

    public MapMarkerDot(double lat, double lon) {
        this(new Color(87, 129, 252), lat, lon);
    }

    public MapMarkerDot(Color color, double lat, double lon) {
        super();
        this.color = color;
        this.lat = lat;
        this.lon = lon;
    }



	public MapMarkerDot(double lat, double lon, long timestamp, double distanceToPreviousMarker) {
		this(new Color(87, 129, 252), lat, lon, timestamp, distanceToPreviousMarker);
		this.lat = lat;
		this.lon = lon;
		this.timestamp = timestamp;
		this.distanceToPreviousMarker = distanceToPreviousMarker;
	}

	public MapMarkerDot(Color color, double lat, double lon, long timestamp, double distanceToPreviousMarker) {
		this.color = color;
		this.lat = lat;
		this.lon = lon;
		this.timestamp = timestamp;
		this.distanceToPreviousMarker = distanceToPreviousMarker;
	}

	public MapMarkerDot(double lat, double lon, long timestamp) {
		this.lat = lat;
		this.lon = lon;
		this.timestamp = timestamp;
	}

	public MapMarkerDot(double lat, double lon, Color color) {
        this.color = color;
        this.lat = lat;
        this.lon = lon;
    }


	public double getLat() {
        return lat;
    }

    public double getLon() {
        return lon;
    }

	public long getTimestamp() {
		return timestamp;
	}

	public double getDistanceToPreviousMarker() {
		return distanceToPreviousMarker;
	}

	public void setIsInLocation(boolean inLocation) {
		isInLocation = inLocation;
	}

	public boolean isInLocation() {
		return isInLocation;
	}

	public int getMapLocationID() {
		return mapLocationID;
	}

	public void setMapLocationID(int mapLocationID) {
		this.mapLocationID = mapLocationID;
	}

	public void paint(Graphics g, Point position) {
	    Graphics2D g2 = (Graphics2D) g;
	    g2.setStroke(new BasicStroke());
//	    g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        int size_h = 5;
        int size = size_h * 2;
		//TODO Check if position.y - 3???
	    Area areaOne = new Area(new Ellipse2D.Double(position.x - size_h, position.y - size_h - 8, size, size));
	    Polygon triangle = new Polygon();
	    triangle.addPoint(position.x - 5, position.y - 7);
	    triangle.addPoint(position.x + 5, position.y - 7);
	    triangle.addPoint(position.x, position.y);
	    Area areaTwo = new Area(triangle);
	    areaOne.add(areaTwo);
        g2.setColor(color);
	    g2.fill(areaOne);
        g2.setColor(Color.BLACK);
	    g2.draw(areaOne);

	    /*int size_h = 5;
        int size = size_h * 2;
        g.setMarkerBackground(markerBackground);
        g.fillOval(position.x - size_h, position.y - size_h, size, size);
        g.setMarkerBackground(Color.BLACK);
        g.drawOval(position.x - size_h, position.y - size_h, size, size);*/
    }

    @Override
    public String toString() {
        return "MapMarker at " + lat + " " + lon;
    }

}
